package net.xdclass.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Classname CartVo
 * @Description TODO
 * @Date 2022/4/27 14:37
 * @Created by sunhao
 */
public class CartVo {

  /**
   * 购物车商品
   */
  private List<CartItemVo> cartItemVoList;

  /**
   * 总价格
   */
  private BigDecimal totalAmount;


  /**
   * 购物车数量
   */
  private Integer totalNum;


  /**
   * 抵扣价格
   */
  private BigDecimal realPayAmount;


  public List<CartItemVo> getCartItemVoList() {
    return cartItemVoList;
  }

  public void setCartItemVoList(List<CartItemVo> cartItemVoList) {
    this.cartItemVoList = cartItemVoList;
  }

  public BigDecimal getTotalAmount() {
    if(this.cartItemVoList != null){
      return this.cartItemVoList.stream().map(CartItemVo::getTotalAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
    }
    return BigDecimal.ZERO;
  }

  public void setTotalAmount(BigDecimal totalAmount) {
    this.totalAmount = totalAmount;
  }

  public Integer getTotalNum() {
    if(this.cartItemVoList != null){
      return cartItemVoList.stream().mapToInt(CartItemVo::getBuyNum).sum();
    }
    return 0;
  }

  public void setTotalNum(Integer totalNum) {
    this.totalNum = totalNum;
  }

  public BigDecimal getRealPayAmount() {
    if(this.cartItemVoList != null){
      return this.cartItemVoList.stream().map(CartItemVo::getTotalAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
    }
    return BigDecimal.ZERO;
  }

  public void setRealPayAmount(BigDecimal realPayAmount) {
    this.realPayAmount = realPayAmount;
  }
}
